package org.colafries.admin.service;

import com.baomidou.mybatisplus.extension.service.IService;
import org.colafries.admin.entity.domain.DataBase;
import org.colafries.admin.entity.vo.ColumnRspVO;
import org.colafries.admin.entity.vo.DataBaseReqVO;
import org.colafries.admin.entity.vo.DataBaseRspVO;
import org.colafries.common.metadata.Column;
import org.colafries.common.metadata.Schema;
import org.colafries.metadata.result.JdbcSelectResult;

import java.util.List;
import java.util.Map;

/**
 * @author colafries
 * @version v1.0
 * @ClassName DataSourceService
 * @Description
 * @date Created in 2024/3/14
 **/
public interface IDataBaseService extends IService<DataBase> {

    /**
     * 查询数据源
     *
     * @param reqVO
     * @return
     */
    List<DataBaseRspVO> getAll(DataBaseReqVO reqVO);

    /**
     * 修改数据源
     *
     * @param reqVO
     * @return
     */
    int update(DataBaseReqVO reqVO);

    /**
     * 新增数据源
     *
     * @param reqVO
     * @return
     */
    int add(DataBaseReqVO reqVO);

    /**
     * 删除数据源
     *
     * @param reqVO
     * @return
     */
    int delete(DataBaseReqVO reqVO);

    /**
     * 测试数据源联通性
     *
     * @param reqVO
     * @return
     */
    Map<String, String> testConnection(DataBaseReqVO reqVO);

    /**
     * 获取数据源的库和表
     *
     * @param reqVO
     * @return
     */
    List<Schema> getSchemasAndTables(DataBaseReqVO reqVO);


    /**
     * 获取表列
     *
     * @param reqVO
     * @return
     */
    List<Column> getTableSchema(DataBaseReqVO dataBaseReqVO);

    /***
     * 查询sql结果
     * @param queryDataReqVO
     * @return org..colafries.admin.metadata.result.JdbcSelectResult
     * @author colafries
     * @Date 2024/3/24
     */
    JdbcSelectResult querySqlPage(Integer databaseId, String querySql, Integer current, Integer size);

    /**
     * 查询sql结果schema
     * @param queryDataReqVO
     * @return java.util.List<org..colafries.admin.entity.vo.ColumnRspVO>
     * @author colafries
     * @Date 2024/4/3
     */
    List<ColumnRspVO> querySqlSchema(Integer databaseId,String querySql);
}
